import { Warning, Link } from '@brillout/docpress'
import { ConfigSpec } from '../../components'

<ConfigSpec
  env="client, server"
  global={null}
/>

Access global information about your app, see <Link href="/globalContext" />.

For example, on the server-side, it can be used to access <Link href="/preloading#assets-manifest">the assets manifest</Link>:

```ts
// Environment: server, client

import { getGlobalContext } from 'vike'

const globalContext = await getGlobalContext()

// The assets manifest
if (!globalContext.isClientSide) console.log(globalContext.assetsManifest)

// Subset of the Vite configuration passed to the runtime. (By default the
// Vite configuration is available only at build-time.)
if (!globalContext.isClientSide) console.log(globalContext.viteRuntimeInfo)
```

`getGlobalContext()` can be invoked at any time, independent of page rendering. For example, it can be one of the first functions called when your server starts — before it even receives any HTTP requests.

> You can also access it <Link href="/pageContext">over `pageContext.globalContext`</Link>.


## `getGlobalContextAsync()`

```ts
import { getGlobalContextAsync } from 'vike'
const globalContext = await getGlobalContextAsync(process.env.NODE_ENV === 'production')
```

Same as `getGlobalContext()`: for some users `getGlobalContext()` cannot be called early and the solution is to use `getGlobalContextAsync()` instead.

We recommend using `getGlobalContext()` instead: use `getGlobalContextAsync()` only if `getGlobalContext()` throws the following error.

```yaml
# For some users, the following error is thrown when running getGlobalContext()
The global context isn't set yet, use getGlobalContextAsync() instead.
```

The returned `globalContext` is the same as the one returned by `getGlobalContext()`.


## `getGlobalContextSync()`

Same as `getGlobalContext()` but synchronous. Only works reliably in production.

<Warning>Don't use it in development: use `getGlobalContext()` or <Link href="/pageContext">`pageContext.globalContext`</Link> instead. If you need `getGlobalContextSync()` in development then reach out on GitHub.</Warning>


## See also

- <Link href="/globalContext" />
- <Link href="/getVikeConfig">API > `getVikeConfig()`</Link>
